package com.tous.tool.model;


import com.tous.tool.utils.ITree;


import java.util.List;

/**
 * @author mengwei
 * @description NodeModel
 * @createDate 2025/6/13 15:05
 */
public class NodeModel implements ITree<NodeModel> {

    // Node code
    private String code;
    // Node name
    private String name;

    // Parent node code
    private String parentCode;

    private List<NodeModel> children;


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getParentCode() {
        return parentCode;
    }

    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    public List<NodeModel> getChildren() {
        return children;
    }

    public void setChildren(List<NodeModel> children) {
        this.children = children;
    }

    @Override
    public boolean isRoot(NodeModel nodeModel) {
        if (nodeModel.getParentCode() == null || nodeModel.getParentCode().equals("")){
            return true;
        }
        return false;
    }

    @Override
    public boolean isChild(NodeModel p, NodeModel child) {
        if (p.getCode().equals(child.getParentCode())){
            return true;
        }
        return false;
    }



    @Override
    public void setChilde(NodeModel nodeModel, List<NodeModel> list) {
        nodeModel.setChildren(list);
    }
}
